{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('./DM_model/DM_char.json', mode='r', encoding='utf-8') as f:\n",
    "    DM_data = json.load(f)\n",
    "\n",
    "with open('./ner_model/char_conv.json', mode='r', encoding='utf-8') as f:\n",
    "    ner_data = json.load(f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Action -> intent_val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "action_intent : ['Control-AC_Mode', 'PAD', 'Control-Humidifier_State', 'inform_mode', 'Control-RangHood_State', 'Control-Humidifier_Gear', 'affirm', 'Control-Fan_Gear', 'inform_Lamp', 'Control-Lamp_State', 'Control-AC_Wind', 'Control-RiceCooker_Timing', 'Control-Fan_Mode', 'Control-AC_Timing', 'whattodo', 'Control-Curtain_State', 'Control-Oven_Mode', 'inform_time', 'Control-Fan_Timing', 'Control-AC_State', 'Control-Humidifier_Timing', 'Control-Lamp_Mode', 'Control-Fan_Wind', 'Control-RiceCooker_State', 'Control-Fan_State', 'inform_sensorvalue', 'whoareyou', 'Control-Lamp_Lightness', 'Control-Oven_State', 'goodbye', 'Control-Lamp_Timing', 'inform_AC', 'Control-Oven_Temp', 'Control-AC_Temp', 'Control-Curtain_Timing', 'inform_range', 'greet', 'Control-RiceCooker_Mode', 'deny', 'Control-Lamp_Color', 'thanks', 'inform_address']  \n",
      "action_intent_len : 42\n"
     ]
    }
   ],
   "source": [
    "action_intent = [i for i in  DM_data['intent2id'].keys()]\n",
    "print('action_intent : {}  \\naction_intent_len : {}'.format(action_intent, len(action_intent)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Action -> action_val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "action_action : ['Control-AC_Mode', 'PAD', 'Control-Humidifier_State', 'utter_answer_goodbye', 'Control-RangHood_State', 'Control-Humidifier_Gear', 'Control-Fan_Gear', 'Control-Lamp_State', 'Control-AC_Wind', 'utter_answer_deny', 'Control-RiceCooker_Timing', 'Control-Fan_Mode', 'Control-AC_Timing', 'utter_answer_whoareyou', 'Control-Curtain_State', 'Control-Oven_Mode', 'Control-Fan_Timing', 'Control-AC_State', 'Control-Humidifier_Timing', 'Control-Lamp_Mode', 'Control-Fan_Wind', 'Control-RiceCooker_State', 'Control-Fan_State', 'utter_answer_whattodo', 'Control-Lamp_Lightness', 'Control-Oven_State', 'Control-Lamp_Timing', 'Control-Oven_Temp', 'Control-AC_Temp', 'Control-Curtain_Timing', 'utter_answer_greet', 'Control-RiceCooker_Mode', 'utter_answer_thanks', 'Control-Lamp_Color', 'utter_answer_affirm']  \n",
      "action_action_len : 35\n"
     ]
    }
   ],
   "source": [
    "action_action = [i for i in  DM_data['action2id'].keys()]\n",
    "print('action_action : {}  \\naction_action_len : {}'.format(action_action, len(action_action)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Ner -> intent_val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ner_intent : ['PADL', 'Control-Lamp_Lightness', 'inform_sensorvalue', 'affirm', 'inform_address', 'Control-Lamp_Timing', 'request_datetime', 'Control-Lamp_Color', 'whattodo', 'inform_color', 'thanks', 'request_weather', 'Control-AC_Mode', 'greet', 'Control-Lamp_Mode', 'Control-Curtain_Timing', 'Control-RiceCooker_Timing', 'Control-Curtain_State', 'Control-AC_Wind', 'goodbye', 'Control-Humidifier_State', 'Control-Humidifier_Timing', 'request_time', 'inform_Lamp', 'Control-AC_Temp', 'whoareyou', 'Control-Oven_Temp', 'inform_range', 'Control-Lamp_State', 'Control-Fan_Mode', 'chitchat', 'Control-AC_State', 'Control-Fan_Gear', 'Control-Fan_Timing', 'Request-Humidifier_Humidity', 'latent_control_temp', 'Control-RiceCooker_Mode', 'Control-RangHood_State', 'Control-RiceCooker_State', 'inform_AC', 'inform_mode', 'inform_time', 'Control-Humidifier_Gear', 'Control-Oven_State', 'deny', 'Control-AC_Timing', 'Control-Fan_State', 'inform_mode ', 'Control-Fan_Wind', 'request_weekday', 'Control-Oven_Mode']  \n",
      "ner_intent_len : 51\n"
     ]
    }
   ],
   "source": [
    "ner_intent = [i for i in  ner_data['intent2id'].keys()]\n",
    "print('ner_intent : {}  \\nner_intent_len : {}'.format(ner_intent, len(ner_intent)))"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    },
    "tags": []
   },
   "source": [
    "PADL:0\n",
    "Control-Fan_Mode:1\n",
    "Control-Curtain_Timing:2\n",
    "inform_address:3\n",
    "Control-Humidifier_Gear:4\n",
    "goodbye:5\n",
    "request_weather:6\n",
    "request_datetime:7\n",
    "request_weekday:8\n",
    "inform_sensorvalue:9\n",
    "Control-AC_Open:10\n",
    "Control-Lamp_Open:11\n",
    "Control-Oven_Mode:12\n",
    "Control-AC_Wind:13\n",
    "inform_Lampcolor:14\n",
    "Control-AC_Timing:15\n",
    "deny:16\n",
    "chitchat:17\n",
    "Control-Fan_State:18\n",
    "Control-AC_Temp:19\n",
    "Control-Lamp_Close:20\n",
    "Control-Humidifier_State:21\n",
    "Control-Curtain_State:22\n",
    "Control-Lamp_Timing:23\n",
    "whattodo:24\n",
    "inform_Lamp:25\n",
    "Control-Lamp_Mode:26\n",
    "whoareyou:27\n",
    "Control-RiceCooker_State:28\n",
    "Request-Humidifier_Humidity:29\n",
    "request_time:30\n",
    "Control-RiceCooker_Mode:31\n",
    "affirm:32\n",
    "Control-Fan_Wind:33\n",
    "Control-Oven_Temp:34\n",
    "Control-Lamp_Lightness:35\n",
    "thanks:36\n",
    "inform_time:37\n",
    "inform_operation:38\n",
    "Control-AC_Close:39\n",
    "Control-Oven_State:40\n",
    "inform_Lampmode:41\n",
    "inform_range:42\n",
    "greet:43\n",
    "Control-RangHood_State:44\n",
    "Control-Fan_Timing:45\n",
    "inform_ACmode:46\n",
    "Control-AC_Mode:47\n",
    "Control-Lamp_Color:48\n",
    "latent_control_temp:49\n",
    "Control-Device_Timing:50\n",
    "Control-Fan_Gear:51\n",
    "Control-RiceCooker_Timing:52\n",
    "inform_AC:53\n",
    "Control-Humidifier_Timing:54"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ner2DM :  ['PADL', 'request_datetime', 'inform_color', 'request_weather', 'request_time', 'chitchat', 'Request-Humidifier_Humidity', 'latent_control_temp', 'inform_mode ', 'request_weekday']\n"
     ]
    }
   ],
   "source": [
    "Ner2DM = []\n",
    "for i in ner_intent:\n",
    "    if i not in action_intent:\n",
    "        Ner2DM.append(i)\n",
    "print('Ner2DM : ', Ner2DM)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "m = int(input())\n",
    "nums = list(map(int, input().split()))\n",
    "temp = 0\n",
    "for i in range(m):\n",
    "    if nums[i] == 1:\n",
    "        temp += 0 \n",
    "    elif nums[i] == 2 or nums[i] == 3:\n",
    "        temp += 1\n",
    "    else:\n",
    "        temp += (nums[i] // 2)\n",
    "print(temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "E, EM, M, MH, H = map(int, input().split())\n",
    "temp = []\n",
    "for i in range(EM+1):\n",
    "    for j in range(MH+1):\n",
    "        temp.append(min(E+i,M+EM+MH-i-j,H+j))\n",
    "print(max(temp) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "strs = input()\n",
    "right = len(strs)-1\n",
    "left = 0\n",
    "res = ''\n",
    "while left <= right:\n",
    "    if strs[left] != strs[right]:\n",
    "        res = strs[left] + res\n",
    "        left += 1\n",
    "    else:\n",
    "        left += 1\n",
    "        right -=1\n",
    "print(strs+res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "T = int(input())\n",
    "for i in range(T):\n",
    "    n = int(input())\n",
    "    a = [int(k) for k in input().split()]\n",
    "    an = 10000000000\n",
    "    def fen(x,n,A,B,C):\n",
    "        global an,a\n",
    "        if C > an:\n",
    "            return\n",
    "        if x == n:\n",
    "            if A == B:\n",
    "                an = min(an, C)\n",
    "            return\n",
    "        fen(x+1, n, A+a[x], B, C)\n",
    "        fen(x+1, n, A, B+a[x], C)\n",
    "        fen(x+1, n, A, B, C+a[x])\n",
    "    fen(0,n,0,0,0)\n",
    "    print(an)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "e,em,m,mh,h=map(int,input().split())\n",
    "opt=(e+em+m+mh+h)//3 # 一开始用int((e+em+m+mh+h)/3)，结果浮点精度爆炸，惨\n",
    "ae,ah=e+em,h+mh # 先全分配给E和H\n",
    "   \n",
    "e2=max(0,min(em,ae-opt)) # E能提供的数目\n",
    "h2=max(0,min(mh,ah-opt)) # H能提供的数目\n",
    "print(min(ae-e2,ah-h2,m+e2+h2)) # 补齐后取最少的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def test2():\n",
    "    s = input()\n",
    "    rev_s = s[::-1]\n",
    "    if s == rev_s:\n",
    "        print(s)\n",
    "        return\n",
    "    len_s = len(s)\n",
    "    for i in range(len_s):\n",
    "        flag = 0\n",
    "        for j in range(i,len_s):\n",
    "            temp_s = s[i:j+1][::-1]\n",
    "             \n",
    "            temp_all = s + temp_s\n",
    "            if temp_all == temp_all[::-1]:\n",
    "                print(temp_all)\n",
    "                flag = 1\n",
    "                break\n",
    "        if flag == 1:\n",
    "            break\n",
    "if __name__ == \"__main__\":\n",
    "    test2()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from collections import Counter\n",
    "\n",
    "with open('/home/ai/hgm/Smart_Home/stories/stories_map.json', mode='r', encoding='utf-8') as f:\n",
    "    stories = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Control-RangHood_State']\n",
      "['operation', 'device']\n",
      "********\n",
      "['Control-RangHood_State']\n",
      "['operation', 'device', 'mode']\n",
      "********\n",
      "['Control-Lamp_Open']\n",
      "['device', 'address', 'operation']\n",
      "********\n",
      "['Control-Lamp_Open']\n",
      "['device', 'operation']\n",
      "********\n",
      "['inform_Lamp', 'Control-Lamp_Open']\n",
      "['device', 'address', 'operation']\n",
      "********\n",
      "['inform_address', 'Control-Lamp_Open']\n",
      "['address', 'device', 'operation']\n",
      "********\n",
      "['inform_range', 'Control-Lamp_Open']\n",
      "['range', 'device', 'operation']\n",
      "********\n",
      "['Control-Lamp_Open']\n",
      "['range', 'device', 'operation']\n",
      "********\n",
      "['Control-Lamp_Open']\n",
      "['operation', 'device']\n",
      "********\n",
      "['inform_address', 'Control-Lamp_Open']\n",
      "['address', 'operation', 'device']\n",
      "********\n",
      "['Control-Lamp_Close']\n",
      "['device', 'address', 'operation']\n",
      "********\n",
      "['Control-Lamp_Close']\n",
      "['device', 'operation']\n",
      "********\n",
      "['inform_Lamp', 'Control-Lamp_Close']\n",
      "['device', 'address', 'operation']\n",
      "********\n",
      "['inform_range', 'Control-Lamp_Close']\n",
      "['range', 'device', 'operation']\n",
      "********\n",
      "['Control-Lamp_Close']\n",
      "['device', 'range', 'operation']\n",
      "********\n",
      "['Control-Lamp_Close']\n",
      "['operation', 'device']\n",
      "********\n",
      "['inform_range', 'Control-Lamp_Close']\n",
      "['range', 'operation', 'device']\n",
      "********\n",
      "['Control-Lamp_Lightness']\n",
      "['operation', 'device']\n",
      "********\n",
      "['inform_address', 'Control-Lamp_Lightness']\n",
      "['address', 'operation', 'device']\n",
      "********\n",
      "['Control-Lamp_Lightness']\n",
      "['operation', 'device', 'address']\n",
      "********\n",
      "['Control-Lamp_Lightness']\n",
      "['sensorvalue', 'device', 'address']\n",
      "********\n",
      "['Control-Lamp_Open']\n",
      "['operation', 'device', 'address']\n",
      "********\n",
      "['Control-Lamp_Lightness', 'Control-Lamp_Open']\n",
      "['sensorvalue', 'operation', 'device', 'address']\n",
      "********\n",
      "['Control-Lamp_Lightness', 'Control-Lamp_Lightness']\n",
      "['sensorvalue']\n",
      "********\n",
      "['Control-Lamp_Lightness', 'Control-Lamp_Open']\n",
      "['device', 'operation']\n",
      "********\n",
      "['inform_sensorvalue', 'Control-Lamp_Open']\n",
      "['sensorvalue', 'operation', 'device', 'address']\n",
      "********\n",
      "['Control-Lamp_Mode']\n",
      "['device', 'address', 'mode']\n",
      "********\n",
      "['Control-Lamp_Color']\n",
      "['device', 'color', 'address']\n",
      "********\n",
      "['Control-Lamp_Mode']\n",
      "['device', 'mode', 'address']\n",
      "********\n",
      "['Control-Lamp_Color']\n",
      "['device', 'address', 'color']\n",
      "********\n",
      "['Control-Lamp_Mode']\n",
      "['device', 'mode']\n",
      "********\n",
      "['inform_address', 'Control-Lamp_Mode']\n",
      "['address', 'device', 'mode']\n",
      "********\n",
      "['Control-Lamp_Color']\n",
      "['device']\n",
      "********\n",
      "['inform_address', 'Control-Lamp_Color']\n",
      "['address', 'device']\n",
      "********\n",
      "['Control-Lamp_Color']\n",
      "['device', 'address', 'target', 'operation', 'color']\n",
      "********\n",
      "['Control-Lamp_Color', 'Control-Lamp_Color']\n",
      "['operation', 'target', 'color', 'device', 'address']\n",
      "********\n",
      "['Control-Lamp_Timing']\n",
      "['time', 'operation', 'device', 'address']\n",
      "********\n",
      "['Control-Lamp_Timing']\n",
      "['operation', 'device', 'address', 'time']\n",
      "********\n",
      "['Control-Lamp_Timing']\n",
      "['time', 'operation', 'device']\n",
      "********\n",
      "['inform_address', 'Control-Lamp_Timing']\n",
      "['address', 'time', 'operation', 'device']\n",
      "********\n",
      "['Control-Fan_State']\n",
      "['device', 'operation']\n",
      "********\n",
      "['Control-Fan_State', 'Control-Fan_State']\n",
      "['address', 'device', 'operation']\n",
      "********\n",
      "['Control-Fan_State']\n",
      "['device', 'operation', 'address']\n",
      "********\n",
      "['Control-Fan_Wind']\n",
      "['operation', 'device']\n",
      "********\n",
      "['Control-Fan_Wind']\n",
      "['sensorvalue', 'device']\n",
      "********\n",
      "['Control-Fan_Gear']\n",
      "['sensorvalue', 'device']\n",
      "********\n",
      "['Control-Fan_Gear']\n",
      "['operation', 'device']\n",
      "********\n",
      "['Control-Fan_Mode']\n",
      "['mode', 'device']\n",
      "********\n",
      "['Control-Fan_Mode']\n",
      "['mode', 'device', 'operation']\n",
      "********\n",
      "['Control-Fan_Timing']\n",
      "['time', 'operation', 'device']\n",
      "********\n",
      "['Control-Fan_State']\n",
      "['operation', 'device']\n",
      "********\n",
      "['Control-Fan_Timing', 'Control-Fan_State']\n",
      "['time', 'operation', 'device']\n",
      "********\n",
      "['Control-Humidifier_State']\n",
      "['operation', 'device']\n",
      "********\n",
      "['Control-Humidifier_Gear']\n",
      "['gear_level', 'device']\n",
      "********\n",
      "['Control-Humidifier_Gear']\n",
      "['operation', 'device']\n",
      "********\n",
      "['Control-Humidifier_Timing']\n",
      "['device', 'time', 'operation']\n",
      "********\n",
      "['Control-RiceCooker_State']\n",
      "['operation', 'device']\n",
      "********\n",
      "['Control-RiceCooker_Mode', 'Control-RiceCooker_State']\n",
      "['device', 'mode', 'operation']\n",
      "********\n",
      "['Control-RiceCooker_Mode']\n",
      "['device', 'mode']\n",
      "********\n",
      "['Control-RiceCooker_Timing', 'Control-RiceCooker_State']\n",
      "['device', 'time', 'operation']\n",
      "********\n",
      "['Control-Curtain_State']\n",
      "['device', 'operation']\n",
      "********\n",
      "['Control-Curtain_State']\n",
      "['device', 'operation', 'sensorvalue']\n",
      "********\n",
      "['Control-Curtain_State']\n",
      "['device', 'operation', 'address']\n",
      "********\n",
      "['Control-Curtain_State']\n",
      "['device', 'operation', 'address', 'sensorvalue']\n",
      "********\n",
      "['Control-Curtain_Timing']\n",
      "['device', 'date_time', 'time', 'operation']\n",
      "********\n",
      "['Control-Curtain_Timing']\n",
      "['device', 'time', 'operation']\n",
      "********\n",
      "['Control-Curtain_Timing']\n",
      "['device', 'date_time', 'time', 'operation', 'sensorvalue']\n",
      "********\n",
      "['Control-Oven_State']\n",
      "['device', 'operation']\n",
      "********\n",
      "['Control-Oven_Mode']\n",
      "['mode', 'device']\n",
      "********\n",
      "['Control-Oven_Temp']\n",
      "['device', 'temperature']\n",
      "********\n",
      "['Control-AC_State']\n",
      "['address', 'device', 'operation']\n",
      "********\n",
      "['Control-Timing', 'Control-AC_State']\n",
      "['time', 'operation', 'address', 'device']\n",
      "********\n",
      "['Control-AC_State']\n",
      "['device', 'operation']\n",
      "********\n",
      "['inform_AC', 'Control-AC_State']\n",
      "['address', 'device', 'operation']\n",
      "********\n",
      "['inform_address', 'Control-AC_State']\n",
      "['address', 'device', 'operation']\n",
      "********\n",
      "['inform_range', 'Control-AC_State']\n",
      "['range', 'device', 'operation']\n",
      "********\n",
      "['Control-AC_State']\n",
      "['range', 'device', 'operation']\n",
      "********\n",
      "['Control-AC_State']\n",
      "['operation', 'device']\n",
      "********\n",
      "['inform_AC', 'Control-AC_State']\n",
      "['device', 'address', 'operation']\n",
      "********\n",
      "['inform_address', 'Control-AC_State']\n",
      "['address', 'operation', 'device']\n",
      "********\n",
      "['inform_range', 'Control-AC_State']\n",
      "['range', 'operation', 'device']\n",
      "********\n",
      "['Control-AC_Mode']\n",
      "['address', 'device', 'mode']\n",
      "********\n",
      "['Control-AC_Mode']\n",
      "['mode']\n",
      "********\n",
      "['inform_AC', 'Control-AC_Mode']\n",
      "['address', 'device', 'mode']\n",
      "********\n",
      "['Control-AC_Mode']\n",
      "['device', 'mode']\n",
      "********\n",
      "['Control-AC_State']\n",
      "['operation', 'device', 'address']\n",
      "********\n",
      "['Control-AC_Mode', 'Control-AC_State']\n",
      "['mode', 'operation', 'device', 'address']\n",
      "********\n",
      "['Control-AC_Mode', 'Control-AC_Mode']\n",
      "['mode']\n",
      "********\n",
      "['Control-AC_Timing']\n",
      "['time', 'operation', 'device', 'address']\n",
      "********\n",
      "['Control-AC_Timing']\n",
      "['time', 'operation', 'device']\n",
      "********\n",
      "['inform_AC', 'Control-AC_Timing']\n",
      "['device', 'address', 'time', 'operation']\n",
      "********\n",
      "['inform_address', 'Control-AC_Timing']\n",
      "['address', 'time', 'operation', 'device']\n",
      "********\n",
      "['Control-AC_Timing']\n",
      "['PAD']\n",
      "********\n",
      "['Control-AC_Timing', 'Control-AC_Timing']\n",
      "['time', 'operation', 'device']\n",
      "********\n",
      "['Control-AC_Timing', 'inform_address']\n",
      "['time', 'operation', 'address']\n",
      "********\n",
      "['Control-AC_Wind']\n",
      "['operation', 'target', 'device', 'address']\n",
      "********\n",
      "['Control-AC_Wind']\n",
      "['sensorvalue', 'target', 'device', 'address']\n",
      "********\n",
      "['Control-AC_Wind']\n",
      "['operation', 'target', 'device']\n",
      "********\n",
      "['inform_address', 'Control-AC_Wind']\n",
      "['address', 'operation', 'target', 'device']\n",
      "********\n",
      "['Control-AC_Wind']\n",
      "['operation', 'device', 'target']\n",
      "********\n",
      "['inform_address', 'Control-AC_Wind']\n",
      "['address', 'operation', 'device', 'target']\n",
      "********\n",
      "['Control-AC_Wind']\n",
      "['operation', 'device', 'address', 'target']\n",
      "********\n",
      "['inform_AC', 'Control-AC_Wind']\n",
      "['device', 'address', 'operation', 'target']\n",
      "********\n",
      "['Control-AC_Wind', 'Control-AC_State']\n",
      "['sensorvalue', 'target', 'operation', 'device', 'address']\n",
      "********\n",
      "['Control-AC_Wind', 'Control-AC_Wind']\n",
      "['sensorvalue', 'target']\n",
      "********\n",
      "['Control-AC_Wind', 'inform_address']\n",
      "['sensorvalue', 'target', 'address']\n",
      "********\n",
      "['Control-AC_Wind', 'Control-AC_State']\n",
      "['device', 'address', 'operation', 'target']\n",
      "********\n",
      "['Control-AC_Wind', 'inform_address']\n",
      "['device', 'address', 'operation', 'target']\n",
      "********\n",
      "['Control-AC_Temp']\n",
      "['device', 'address', 'operation', 'temperature']\n",
      "********\n",
      "['Control-AC_Temp']\n",
      "['address', 'device', 'operation', 'temperature']\n",
      "********\n",
      "['Control-AC_State']\n",
      "['device', 'address', 'operation']\n",
      "********\n",
      "['Control-AC_Temp', 'Control-AC_State']\n",
      "['device', 'operation', 'temperature', 'address']\n",
      "********\n",
      "['Control-AC_Temp', 'Control-AC_Temp']\n",
      "['device', 'operation', 'temperature']\n",
      "********\n",
      "['Control-AC_State', 'Control-AC_Temp']\n",
      "['operation', 'device', 'temperature']\n",
      "********\n",
      "['Control-AC_Temp']\n",
      "['device', 'operation', 'temperature']\n",
      "********\n",
      "['inform_AC', 'Control-AC_Temp']\n",
      "['device', 'address', 'operation', 'temperature']\n",
      "********\n",
      "['inform_address', 'Control-AC_Temp']\n",
      "['address', 'device', 'operation', 'temperature']\n",
      "********\n",
      "['Control-AC_Temp', 'inform_AC']\n",
      "['temperature', 'target', 'address', 'device']\n",
      "********\n",
      "['inform_AC', 'Control-AC_State']\n",
      "['address', 'operation', 'device']\n",
      "********\n",
      "['Control-AC_Temp', 'inform_AC']\n",
      "['target', 'operation', 'address']\n",
      "********\n",
      "['Control-AC_Temp']\n",
      "['device', 'target', 'operation']\n",
      "********\n",
      "['inform_address', 'Control-AC_Temp']\n",
      "['address', 'device', 'target', 'operation']\n",
      "********\n",
      "['inform_address', 'Control-Curtain_State']\n",
      "['address', 'device', 'operation']\n",
      "********\n",
      "['Control-Curtain_Timing']\n",
      "['device', 'operation', 'time']\n",
      "********\n",
      "['Control-Timing', 'Control-Curtain_State']\n",
      "['operation', 'time', 'device']\n",
      "********\n",
      "['Control-RiceCooker_State']\n",
      "['device', 'operation']\n",
      "********\n",
      "['Control-RiceCooker_Mode', 'Control-RiceCooker_State']\n",
      "['mode', 'device', 'operation']\n",
      "********\n",
      "['inform_mode', 'inform_address']\n",
      "['mode', 'address']\n",
      "********\n",
      "['Control-Oven_Mode', 'Control-Oven_State']\n",
      "['mode', 'device', 'operation']\n",
      "********\n",
      "['Control-Oven_Temp', 'Control-Oven_Mode']\n",
      "['device', 'operation', 'temperature', 'mode']\n",
      "********\n",
      "['Control-AC_Temp', 'Control-AC_State']\n",
      "['temperature', 'device', 'operation']\n",
      "********\n",
      "['Control-Fan_Mode', 'Control-Fan_State']\n",
      "['mode', 'operation', 'device']\n",
      "********\n",
      "['greet']\n",
      "['PAD']\n",
      "********\n",
      "['affirm', 'greet']\n",
      "['PAD']\n",
      "********\n",
      "['deny', 'greet']\n",
      "['PAD']\n",
      "********\n",
      "['deny']\n",
      "['PAD']\n",
      "********\n",
      "['goodbye']\n",
      "['PAD']\n",
      "********\n",
      "['thanks', 'greet']\n",
      "['PAD']\n",
      "********\n",
      "['thanks']\n",
      "['PAD']\n",
      "********\n",
      "['whoareyou', 'greet']\n",
      "['PAD']\n",
      "********\n",
      "['whoareyou']\n",
      "['PAD']\n",
      "********\n",
      "['whattodo']\n",
      "['PAD']\n",
      "********\n",
      "['whattodo', 'greet']\n",
      "['PAD']\n",
      "********\n"
     ]
    }
   ],
   "source": [
    "for val in stories:\n",
    "    print(val['storys'][1])\n",
    "    print(val['storys'][0])\n",
    "    print('********')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "**********************第1轮对话 开始**********************\n",
    "User:打开餐厅灯\n",
    "2021-08-25 11:35:30.682406: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10\n",
    "2021-08-25 11:35:30.785382: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.7\n",
    "intent:Control-Lamp_Open \n",
    " slot:{'operation': '打开', 'address': '餐厅', 'device': '灯'}\n",
    "模式选择 rule\n",
    "*************\n",
    "intent:  Control-Lamp_Open\n",
    "action: Control-Lamp_State\n",
    "match_device:  ['Lamp']\n",
    "*************\n",
    "match_device: ['Lamp']\n",
    "action : Control-Lamp_State \n",
    "BotUtterence: 正在为您打开餐厅灯\n",
    "**********************第2轮对话 开始**********************\n",
    "User:开灯\n",
    "intent:Control-Lamp_Open \n",
    " slot:{'operation': '开', 'device': '灯'}\n",
    "模式选择 rule\n",
    "*************\n",
    "intent:  Control-Lamp_Open\n",
    "action: Control-Lamp_State\n",
    "match_device:  ['Lamp']\n",
    "*************\n",
    "match_device: ['Lamp']\n",
    "action : Control-Lamp_State \n",
    "BotUtterence: 正在为您开餐厅灯\n",
    "**********************第3轮对话 开始**********************\n",
    "User:关灯\n",
    "intent:Control-Lamp_Close \n",
    " slot:{'operation': '关', 'device': '灯'}\n",
    "　text: [['Control-Lamp_State'], ['address', 'device', 'operation'], ['Control-Lamp_Open', 'Control-Lamp_Close']] \n",
    " action:Control-AC_Timing \n",
    " \n",
    "模式选择 mode\n",
    "*************\n",
    "intent:  Control-Lamp_Close\n",
    "action: Control-AC_Timing\n",
    "match_device:  ['Lamp']\n",
    "*************\n",
    "match_device: ['Lamp']\n",
    "action : Control-Lamp_Timing \n",
    "BotUtterence: 请问要定时多长时间\n",
    "**********************第4轮对话 开始**********************\n",
    "User:关闭餐厅灯\n",
    "intent:Control-Lamp_Close \n",
    " slot:{'operation': '关闭', 'address': '餐厅', 'device': '灯'}\n",
    "　text: [['Control-Lamp_Timing'], ['address', 'device', 'operation'], ['Control-Lamp_Open', 'Control-Lamp_Close']] \n",
    " action:Control-AC_Timing \n",
    " \n",
    "模式选择 mode\n",
    "*************\n",
    "intent:  Control-Lamp_Close\n",
    "action: Control-AC_Timing\n",
    "match_device:  ['Lamp']\n",
    "*************\n",
    "match_device: ['Lamp']\n",
    "action : Control-Lamp_Timing \n",
    "BotUtterence: 请问要定时多长时间\n",
    "**********************第5轮对话 开始**********************\n",
    "User:三小时\n",
    "intent:inform_time \n",
    " slot:{'time': '三小时'}\n",
    "Traceback (most recent call last):\n",
    "  File \"/home/ai/hgm/Smart_Home/main_v1.py\", line 31, in <module>\n",
    "    action = [DM.predict(tracker)]\n",
    "  File \"/home/ai/hgm/Smart_Home/predict_DM/predict_DM.py\", line 69, in predict\n",
    "    user_intent_inputs = trans2labelid(intent2id,user_intent_inputs)\n",
    "  File \"/home/ai/hgm/Smart_Home/predict_DM/predict_DM.py\", line 54, in trans2labelid\n",
    "    labels = [vocab[label] for label in x]\n",
    "  File \"/home/ai/hgm/Smart_Home/predict_DM/predict_DM.py\", line 54, in <listcomp>\n",
    "    labels = [vocab[label] for label in x]\n",
    "KeyError: 'inform_time'\n",
    "\n",
    "Process finished with exit code 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
